package com.lkd.controller;


import com.lkd.entity.Sku;
import com.lkd.service.SkuService;
import com.lkd.vo.PageBean;
import com.lkd.vo.Result;
import com.lkd.vo.SkuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-08-19
 */
@RestController
public class SkuController {

    @Autowired
    private SkuService skuService;

    //新增商品
    @PostMapping("/api/vm-service/sku")
    public Result add (@RequestBody Sku sku) {
        boolean save = skuService.save (sku);
        return Result.success (save);
    }
    //查询商品
    @GetMapping("/api/vm-service/sku/search")
    public Result selectByPage(
            String skuName,
            @RequestParam(defaultValue = "1") Integer pageSize,
            @RequestParam(defaultValue = "10")Integer pageIndex
    ){
        PageBean<SkuVo> pageBean = skuService.selectByPage (skuName,pageIndex,pageSize);
        return Result.success (pageBean);
    }


    @GetMapping("/api/vm-service/sku")
    public Result update(@RequestBody Sku sku){
        boolean update = skuService.updateById (sku);
        return Result.success (update);
    }

}
